{% extends 'eform_base_no_nav.html' %}
{% load static %}
{% load i18n %}

{% block title %}
    <title>Form -  CHECK SHEET (Banknote Acceptor, BNA56 & BNA57)</title>
{% endblock title %}

{% block head %}
<!-- <link rel='stylesheet' href='https://cdn.form.io/formiojs/formio.full.min.css'> -->
<link rel='stylesheet' href="{% static 'eform/formio.full.min.css' %}">
<style>
    .staff-name{
        
        min-width:180px;
        display: inline-block;
        margin: 0 50px 0 50px;
    }
    .bold-900{
        font-weight: 900 !important;
        font-size: large;
        text-transform: none;
    }
    strong{
        font-weight:900 !important;
    }
    .modal strong{
        font-size:larger;
    }
</style>
{% endblock head %}
    

{% block body %}
<a class="gnslogo p-3" href="{% url 'workstation_wo' eform.workOrderList %}" >
    <img src="{% static 'cews_static/css/media/Corporate_logo.png' %}">
</a> 
<!-- <div class="container-fluid mt-3">
    <button type="button" id="log-data" class="btn btn-primary">Log Data</button>
</div> -->

<div class="container-fluid sticky">
    <div class="row mt-3">
        <div class="col-auto">
            <a name="" id="" class="btn btn-primary" href="{% url 'workstation_wo' eform.workOrderList %}" role="button"> <i class="fa fa-backward" aria-hidden="true"></i> BACK</a>
        </div>
        <div class="col text-right">
            
            <form action="" method="post" id="eform">
                {% csrf_token %}
                <input type="hidden" name="action" id="eform-action" value="{{eform.overall_test_result}}">
                <input type="hidden" name="dataJson" id="eform-data" value="">
                {% if check_require %}
                    <input type="hidden" name="overall_test_result" id="form-otr" value="{{eform.overall_test_result}}">
                    <input type="hidden" name="user_id" id="eform-user-id" value="-1">
                    
                    <button type="button" value="reset" id="btn-reset" class=" btn btn-danger shadow">RESET</button>
                    <button type="button" value="delete" id="btn-delete" class=" btn btn-danger shadow">DELETE</button>
                    <button type="button" value="save" class="save-btn btn btn-success shadow">SAVE</button>
                    <button type="button" value="{{check_type}}" class="text-uppercase check-btn btn btn-info shadow">{{check_string}}</button>
                {% else %}
                
                    {% if revise_enable %}
                        <button type="button" value="save" class="save-btn btn btn-success shadow">SAVE</button>
                    {% else %}
                        <button type="button" value="revise" id="btn-revise" class=" btn btn-danger shadow">REVISE</button>
                    {% endif %}
                    
                {% endif %}
                    <a name="" id="" class="btn btn-primary" href="{% url 'eform:printEform' eform.pk %}" target="_blank" role="button">PRINT</a>
                </div>
            </div>
        </div>
        
        <div class="container-fluid mt-3">
            
            {% if message %}
            <div class="alert 
            
            {% if color %}
            alert-{{color}}
            {% else %}
            alert-success
            {% endif %}
            
            alert-dismissible fade show" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <strong>{{message}}</strong> 
        </div>
        
        <script>
            $(".alert").alert();
            </script>
       {% endif %}
       
       <div class="card">
           
           <div class="card-header no-print">
               <h1>{{eform.eformSchema.title}}</h1>
            </div>
            <div class="card-body">
        
                <div class="row">
                    <div class="col-lg-4 col-12">
                        <div class="form-group">
                            <label for="form_no">Form No.</label>
                            <input type="text" readonly value="{{eform.eformSchema.formNo}} {% if eform.eformSchema.issue %}({{eform.eformSchema.issue}}){% endif %}" 
                            class="form-control" name="form_no" id="form_no" aria-describedby="form_no" placeholder="Form No.">
                        </div>
                    </div>
                    
                
                
                    <div class="col-lg-4 col-12">
                        <div class="form-group">
                            <label for="ref">Ref.</label>
                            <input type="text" readonly value="{{eform.eformSchema.ref}}"
                            class="form-control" name="ref" id="ref" aria-describedby="ref" placeholder="Ref">
                        </div>
                    </div>

                    <div class="col-lg-4 col-12">
                        <div class="form-group">
                            <label for="ref">Form Issue Date</label>
                            <input type="text" readonly value="{{eform.eformSchema.form_issue_date|date:'Y-m-d'}}"
                            class="form-control" >
                        </div>
                    </div>

                    {% comment %} <div class="col-lg-6 col-12">
                        <div class="form-group">
                            <label for="">Endorse Require</label>
                            <input type="text" readonly value="{{eform.eformSchema.get_endorsor_require_display}}"
                            class="form-control" name="ref" id="ref" aria-describedby="ref" placeholder="Ref">
                        </div>
                    </div> {% endcomment %}
                </div>
                    
                <hr>
                <div class="row">
                    <div class="col-sm-12 col-md-3 ">
                        <div class="form-group">
                          <label for="">Serial Number</label>
                          <input value="{{eform.workOrderList.brokenpart.serialno|default:''}}"
                          type="text" class="form-control" readonly name="line_w_order" id="id_line_w_order" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>
                    <div class="col-sm-12 col-md-3 ">
                        <div class="form-group">
                          <label for="">Location</label>
                          <input value="{{eform.workOrderList.location|default:''}}"
                          type="text" class="form-control" readonly name="location" id="id_location" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>
                   <div class="col-sm-12 col-md-3 ">
                        <div class="form-group">
                            <label for="">FAILURE SYMPTOM</label>
                            <input form="eform" value="{{eform.workOrderList.failure_sym|default:''}}" readonly
                            type="text" class="form-control"  name="wo_failure_sym" id="id_failure_sym" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                    <div class="col-sm-12 col-md-3 ">
                        <div class="form-group">
                          <label for="">RECEIVED DATE</label>
                          <input value="{{eform.workOrderList.received_date|date:'Y-m-d'}}"
                          type="text" class="form-control" readonly name="report_date" id="id_report_date" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>

                </div>
                <div class="row">
                    <div class="col-sm-12 col-md-3 ">
                        <div class="form-group">
                          <label for="">LINE ORDER</label>
                          <input value="{{eform.workOrderList.line_w_order|default:''}}"
                          type="text" class="form-control" readonly name="line_w_order" id="id_line_w_order" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>
                    <div class="col-sm-12 col-md-3 ">
                        <div class="form-group">
                        <label for="">CEWS ORDER</label>
                        <input value="{{eform.workOrderList.cews_w_order}}"
                        type="text" class="form-control" readonly name="cews_w_order" id="id_cews_w_order" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>
                    
                     <div class="col-sm-12 col-md-6 ">
                        <div class="form-group">
                            <label for="">CHECKED DATE</label>
                            <input value="{{eform.workOrderList.checkout_date|date:'Y-m-d'}}"
                            type="text" class="form-control" readonly name="received_date" id="id_received_date" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                </div> 
                
                {% comment %} <div class="row">
                    
                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                          <label for="">Work Order Type</label>
                          <input value="{{eform.workOrderList.wo_type|default:''}}"
                          type="text" class="form-control" readonly name="wo_type" id="id_wo_type" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>

                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                          <label for="">EQPT./CAR NO.</label>
                          <input value="{{eform.workOrderList.carno|default:''}}"
                          type="text" class="form-control" readonly name="carno" id="id_carno" aria-describedby="helpId" placeholder="">
                        </div>    
                    </div>
                          
                    
                    
                    
                    <div class="col">
                        <div class="form-group">
                            <label for="">EQPT. DESCRIPTION</label>
                            <input value="{{eform.workOrderList.eqip_des|default:''}}"
                            type="text" class="form-control" readonly name="eqip_des" id="id_eqip_des" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                  
                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                            <label for="">RETURN TO</label>
                            <input value="{{eform.workOrderList.return_to|default:''}}"
                            type="text" class="form-control" readonly name="return_to" id="id_return_to" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>

                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                            <label for="">CREATE STAFF</label>
                            <input value="{{eform.workOrderList.create_staff}}"
                            type="text" class="form-control" readonly name="create_staff" id="id_create_staff" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                   
                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                            <label for="">WO RESULT</label>
                            <input value="{{eform.workOrderList.wo_result|default:''}}"
                            type="text" class="form-control" readonly name="wo_result" id="id_wo_result" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>


                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                            <label for="">CONTRACTOR ORDER NO.</label>
                            <input value="{{eform.workOrderList.contractor_ref_order|default:''}}"
                            type="text" class="form-control" readonly name="contractor_ref_order" id="id_contractor_ref_order" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                            <label for="">CHECK OUT DATE</label>
                            <input value="{{eform.workOrderList.checkout_date|default:''}}"
                            type="text" class="form-control" readonly name="checkout_date" id="id_checkout_date" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                    <div class="col-sm-12 col-md-4 ">
                        <div class="form-group">
                            <label for="">SEND OUT LOCATION</label>
                            <input value="{{eform.workOrderList.sendout_location|default:''}}"
                            type="text" class="form-control" readonly name="sendout_location" id="id_sendout_location" aria-describedby="helpId" placeholder="">
                          </div>    
                    </div>
                    
                   


                    
                    

                </div> {% endcomment %}

            </div>
            
            
        </div>
        </form>
        <br>
        
        <div class="card">
            <div class="card-header">
             <div class="row ">
                 <div class="col">
                     <h4>Applied IMTE</h4>
                 </div>
                 <div class="col text-right">
                     <button type="button" id="btn-scan-imte" class="btn btn-sm btn-primary">SCAN</button>
                 </div>
             </div>
            </div>
            <br>
            <div class="card-body">
             
             <table class="table table-bordered">
                 <thead>
                     <tr>
                         <th>
                             E.I. / EWS No.
                         </th>
                         <th>
                             DUE DATE
                         </th>
                     </tr>
                 </thead>
                 <tbody id="imte-tbody">
                     
                     {% for data in imtes %}
                     <tr id="tr-{{data.imte}}">
                         <td>
                         {{data.imte}}
                         </td>
                    
                         <td>
                         {{data.due_date|date:'Y-m-d'}}
                         </td>
                    
                         <td class="text-center">
                             <button type="button" class="btn btn-sm imte-delete  btn-primary px-2 py-2" data-imte="{{data.imte}}"><i class="fa fa-times" aria-hidden="true"></i></button>
                         </td>
                     </tr>
                     {% endfor %}
                         
                 </tbody>
 
             </table>
            </div>

        </div>
        <br>
            <div class="card ">
                <div class="card-body ">
                    <div id="formio">
                    </div>
                </div>
            </div>

            <div class="card mb-3 pt-0 ">
                    
                <div class="card-body pt-3">
                    
                    
                    
                    
    
                    <div class="row mt-3">
    
                        {% comment %} <div class="col-6">
                            <div class="form-group">
                                <label for="">FAILURE SYMPTOM</label>
                                <input form="eform" value="{{eform.workOrderList.failure_sym|default:''}}"
                                type="text" class="form-control"  name="wo_failure_sym" id="id_failure_sym" aria-describedby="helpId" placeholder="">
                              </div>    
                        </div> {% endcomment %}
    
                        <div class="col-3">
                            <div class="form-group">
                                <label for="">FINDING</label>
                                <input 
                                {% if not revise_enable %}
                                    readonly
                                {% endif %}
                                     form="eform" value="{{eform.workOrderList.finding|default:''}}"
                                type="text" class="form-control"  name="wo_finding" id="id_finding" aria-describedby="helpId" placeholder="">
                              </div>    
                        </div>

                        <!-- Updated by Dorothy - action pulldown list for action field -->

                        {% comment %}
                        <div class="col-6">
                            <div class="form-group">
                                <label for="">ACTION</label>
                                <input form="eform" value="{{eform.workOrderList.action|default:''}}"
                                type="text" class="form-control"  name="wo_action" id="id_action" aria-describedby="helpId" placeholder="">
                              </div>    
                        </div>
                        {% endcomment %}
                        
                        <div class="col-3">
                            <div class="form-group">
                                <label for="id_finding_opt">ACTION <span style="color:red">*</span></label>

                                <select 
                                {% if not revise_enable %}
                                    disabled
                                {% endif %}
                                class="form-control wo-fields" form="eform"  name="wo_finding_opt" id="id_finding_opt">
                                    <option value="">---------</option>
                                    {% for f in eform.workOrderList.FINDING_CHOICES %}
                                        <option value="{{f.0}}" 
                                        {% if f.0 == eform.workOrderList.finding_opt %}
                                            selected
                                        {% endif %}
                                            >{{f.1}}</option>
                                    {% endfor %}
                                </select>

                            </div>    
                        </div>
                        
                        <div class="col-3">
                            <div class="form-group">
                                <label for="id_fault_opt">FAULT <span style="color:red">*</span></label>
                                <select 
                                {% if not revise_enable %}
                                    disabled
                                {% endif %}
                                class="form-control wo-fields" form="eform"  name="wo_fault_opt" id="id_fault_opt">
                                    <option value="">---------</option>
                                    {% for fo in eform.workOrderList.FAULT_CHOICES %}
                                        <option value="{{fo.0}}" 
                                        {% if fo.0 == eform.workOrderList.fault_opt %}
                                            selected
                                        {% endif %}
                                            >{{fo.1}}</option>
                                    {% endfor %}
                                </select>
                            </div>    
                        </div>
                        
                        
                        <div class="col-3">
                            <div class="form-group">
                                <label for="id_fault_action">FAULT REMARKS <span style="color:red">*</span></label>
                                <input 
                                    
                                    {% if not revise_enable %}
                                        readonly
                                    {% endif %}
                                        
                                form="eform" value="{{eform.workOrderList.fault_action}}"
                                type="text" class="form-control"  name="wo_fault_action" id="id_fault_action" aria-describedby="helpId" placeholder="">
                              </div>    
                        </div>
                        {% comment %} <div class="col-6">
                            <div class="form-group">
                                <label for="">REMARKS</label>
                                <input form="eform" value="{{eform.workOrderList.remarks|default:''}}"
                                type="text" class="form-control" name="wo_remarks" id="id_remarks" aria-describedby="helpId" placeholder="">
                              </div>    
                        </div> {% endcomment %}
                    
                    </div>
    
                    <div class="row">
                        <div class="col text-center">
                            <strong>Overall Test Result: <span style="color:red">*</span></strong>
                            <div class="form-check form-check-inline mt-0">
                                <label class="form-check-label">
                                    <input class="form-check-input meta-input " form="eform" required
                                    {% if eform.overall_test_result == 'Pass' %}
                                        checked
                                    {% endif %}
                                         type="radio" name="overall_test_result_radio" id="" value="Pass"> Pass
                                    <input class="form-check-input meta-input " form="eform" required
                                    {% if eform.overall_test_result == 'Fail' %}
                                        checked
                                    {% endif %}
                                     type="radio" name="overall_test_result_radio" id="" value="Fail"> Fail
                                </label>
                            </div>
                        </div>
                    </div>
                    <br>

                    <div class="row text-center card-header">
                        <div class="col text-center">
                            <div class="staff-name">
                                
                                <small>Done By</small>
                                <h5>{{eform.doneby}}</h5>
                                <hr>
                                <p>{{eform.doneDate}}</p>
                            </div>
                            {% if eform.eformSchema.endorsor_require %}
                            <div class="staff-name">
                                <small>Verified By</small>
                                <h5>{{eform.verifiedby}}</h5>
                                <hr>
                                <p>{{eform.verifiedDate}}</p>
                            </div>
                            <div class="staff-name">
                                
                                <small>Endorsed By</small>
                                <h5>{{eform.endorsedby}}</h5>
                                <hr>
                                <p>{{eform.endorsedDate}}</p>
                            </div>
                            {% endif %} 
                        </div>
                    </div>
                    <br>
                    <div class="row text-center">
                        <div class="col">
                            <strong class="">End of Test</strong>
                        </div>
                    </div>
    
                </div>
            </div>
            <!-- image -->
            {% if eformFile.count %}
            <div class="card">
                <div class="card-header">Uploaded Image</div>
                <div class="card-body">
                    
                    <table class="table" id="">
                        <tr>
                            <th>File</th>
                        </tr>
                        <tbody id="uploaded_image_body">
                            
                            {% for f in eformFile %}
                                <tr id="eformFile-{{f.id}}">
                                    <td>
                                        {% if f.isImage %}
                                            
                                            <img src="{{f.file.url}}" class="" height="100px" alt="">
                                        {% endif %}
                                        {% if f.isVideo %}
                                            <video src="{{f.file.url}}" class="" height="100px" alt=""></video>
                                        {% endif %}
                                        <a href="{{f.file.url}}" target="_blank">
                                            {{f.filename}}
                                        </a>
                                    </td>
                                 
                                </tr>
                            {% empty %}
                                <td>
                                    <tr>No File</tr>
                                </td>
                            {% endfor %}
                                
                        </tbody>
                    </table>
                    
                </div>
            </div>
            {% endif %}
            {% if rlog.count > 0 %}
                
            <br>
            <div id="rolog" role="tablist" aria-multiselectable="true">
                <div class="card">
                    <div class="card-header" role="tab" id="rlogheasder">
                        <h5 class="mb-0">
                            <a data-toggle="collapse" data-parent="#rolog" href="#rlogcontent" aria-expanded="true" aria-controls="rlogcontent">
                                {% trans 'Revise Log' %}
                            </a>
                        </h5>
                    </div>
                    <div id="rlogcontent" class="collapse in show" role="tabpanel" aria-labelledby="rlogheasder">
                        <div class="card-body">
                            <ul>
                                
                                {% for r in rlog %}
                                    <li>{{r}}</li>
                                {% endfor %}
                                
                            </ul>
                        </div>
                    </div>
                </div>
                
            </div>
            <br>
            {% endif %}
    </div>
    
    <!-- Modal -->
    <div class="modal  fade" id="choose-check-user-modal" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{check_string}} Eform</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                </div>
                <div class="modal-body mx-auto">
                    <button id="check_as_other" type="button" class="btn  btn-info">{{check_string}} As Other User</button>
                    <button type="button" class="btn  btn-success" value="{{check_type}}" id="check-current-user">{{check_string}} As Current User</button>
                </div>
            </div>
        </div>
    </div>

   
    <div class="modal fade" id="scan_modal" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content m-0 bg-dark">
                <div class="modal-header bg-light">
                    <h5 class="modal-title">SCAN STAFF QRCODE</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                </div>
                <div id="scan_modal__alert">
                </div>
                <video id="preview" class="d-none"></video>
                <canvas id="preview__canvas"></canvas>
                <button type="button" name="" id="final_check_as_other" disabled class="btn btn-primary m-0 " btn-lg btn-block">
                    <span id="checkbutton-text" class="">Scanning ... </span>
                    <span class="bold-900" id="scaned_username"></span>
                </button>
            </div>
        </div>
    </div>
{% endblock body %}



{% block script %}
<!-- <script src='https://cdn.form.io/formiojs/formio.full.min.js'></script> -->
<script>
    let dataJson={{formSchema | safe}}
    let data = {{eform.getFormDataJson |safe}}
    const getCheckUser_url = `{% url 'api:user_getcheckuser' %}`
    const getResetEndorsed_url = `{% url 'api:eform_resetEndorsed' %}`
    const route = `{% url 'eform:eformRoutingView' eform.workOrderList_pk %}`
    const eform_id = {{eform.id}}
    const revise = '{{revise_enable}}'
</script>
<script src="{% static 'eform/formio.full.min.js' %}"></script>
<script src="{% static 'api/axios.min.js' %}"></script>
<script src="{% static 'eform/instascan.min.js' %}"></script>
<script src="{% static 'eform/gnsScan.js' %}"></script>
<script src="{% static 'eform/cameraUSER.js' %}"></script>
<script src="{% static 'eform/confirm.js' %}"></script>
<script src="{% static 'eform/checkEform.js' %}"></script>
<script src="{% static 'eform/wo_action.js' %}"></script>


{% endblock script %}
    
    